<template>
  <div>
    <component
      :is="componentName"
      @updateResource="updateResource"
      @submitData="submitData"
      :update="updateFlag"
      :authPass="authPass"
    ></component>
  </div>
</template>

<script lang="ts" setup>
import authResourceIndex from "./authResourceIndex.vue";
import authingComp from "@/pages/home/registerLogin/accountRegister/authing.vue";
import authingResult from "@/pages/home/registerLogin/accountRegister/authingResult.vue";
import noAuthComp from "@/pages/home/registerLogin/accountRegister/noAuth.vue";
import freezeComp from "@/pages/home/registerLogin/accountRegister/freeze.vue";
import { companyCheck } from "@/service/dp.ts";
const componentName: any = ref("");
const authPass = ref(false)
const updateFlag: any = ref(false);
async function getCompanyStatus() {
  let res: any = await companyCheck();
  if (res.code == 1101) {
    // 认证待审核
    componentName.value = authingComp;
  } else if (res.code == 1102) {
    // 认证被驳回
    componentName.value = authingResult;
  } else if (res.code == 1100) {
    // 企业尚未认证
    componentName.value = noAuthComp;
  } else if (res.code == 1103) {
    // 被冻结
    componentName.value = freezeComp;
  } else if(res.code == 200) {
    // 认证通过
    componentName.value = authResourceIndex;
    updateFlag.value = true;
    authPass.value = true;
  }else{
    componentName.value = authResourceIndex;
  }
}

function updateResource(val: any) {
  componentName.value = authResourceIndex;
  updateFlag.value = val;
}

function submitData() {
  getCompanyStatus();
}
onMounted(() => {
  getCompanyStatus();
});
</script>

<style scoped lang="scss"></style>
